<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="后台管理功能：添加分类、修改分类">
<meta property="og:type" content="article">
<meta property="og:title" content="blog （四）">
<meta property="og:url" content="http://example.com/2021/04/06/blog-%EF%BC%88%E5%9B%9B%EF%BC%89/index.html">
<meta property="og:site_name" content="yyc&#39;s blog">
<meta property="og:description" content="后台管理功能：添加分类、修改分类">
<meta property="og:locale">
<meta property="og:image" content="https://gitee.com/goatyyc/giteep-page-imgs/raw/master/imgs/20210406111324.png">
<meta property="article:published_time" content="2021-04-06T03:14:29.000Z">
<meta property="article:modified_time" content="2021-04-06T03:16:03.795Z">
<meta property="article:author" content="yyc">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/goatyyc/giteep-page-imgs/raw/master/imgs/20210406111324.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://example.com/2021/04/06/blog-（四）/"/>





  <title>blog （四） | yyc's blog</title>
  








<meta name="generator" content="Hexo 5.3.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta custom-logo">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">yyc's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术博客</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/06/blog-%EF%BC%88%E5%9B%9B%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yyc's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">blog （四）</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2021-04-06T11:14:29+08:00">
                2021-04-06
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/springboot/" itemprop="url" rel="index">
                    <span itemprop="name">springboot</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="后台管理功能：添加分类、修改分类"><a href="#后台管理功能：添加分类、修改分类" class="headerlink" title="后台管理功能：添加分类、修改分类"></a>后台管理功能：添加分类、修改分类</h2><a id="more"></a>

<h3 id="1、发表文章（增加分类）"><a href="#1、发表文章（增加分类）" class="headerlink" title="1、发表文章（增加分类）"></a>1、发表文章（增加分类）</h3><p>上一回发布文章后还遗留分类问题、新增文章返回id为空的问题</p>
<p>返回的自增主键：</p>
<p>在mapper.xml的插入语句添加<code>useGeneratedKeys=&quot;true&quot; keyProperty=&quot;id&quot;</code></p>
<p>分类问题：</p>
<p>之前渲染的页面已经传入了categories</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// ArticleController</span></span><br><span class="line"></span><br><span class="line">    <span class="meta">@GetMapping(&quot;/publish&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">newArticle</span><span class="params">(HttpServletRequest request)</span></span>&#123;</span><br><span class="line">        MetaCond metaCond = <span class="keyword">new</span> MetaCond();</span><br><span class="line">        metaCond.setType(Types.CATEGORY.getType());</span><br><span class="line">        List&lt;Meta&gt; metas = metaService.getMetas(metaCond);</span><br><span class="line">        request.setAttribute(<span class="string">&quot;categories&quot;</span>,metas);</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;admin/article_edit&quot;</span>;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>控制器调用metaService查询了metaCond的name、type信息，并赋值给categories</p>
<p>前端获取到categories并渲染，使用户可以选择分类</p>
<h3 id="2、数据库设计"><a href="#2、数据库设计" class="headerlink" title="2、数据库设计"></a>2、数据库设计</h3><p>content 与 metas的关系：一对多</p>
<p>一篇文章可以属于多个分类、标签</p>
<p><img src="https://gitee.com/goatyyc/giteep-page-imgs/raw/master/imgs/20210406111324.png"></p>
<p><strong>文章添加分类功能：</strong></p>
<p>发布文章后获取新增文章cid</p>
<p>调用metaService添加 addMetas方法</p>
<p>addMetas方法：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addMetas</span><span class="params">(Integer cid, String names, String type)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(<span class="keyword">null</span> == cid)</span><br><span class="line">        <span class="keyword">throw</span> BusinessException.withErrorCode(ErrorConstant.Common.PARAM_IS_EMPTY);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(StringUtils.hasLength(names) &amp;&amp; StringUtils.hasLength(type))&#123;</span><br><span class="line">        String[] nameArr = org.thymeleaf.util.StringUtils.split(names, <span class="string">&quot;,&quot;</span>);</span><br><span class="line">        <span class="keyword">for</span> (String name : nameArr) &#123;</span><br><span class="line">            <span class="keyword">this</span>.saveOrUpdate(cid, name, type);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<p>遍历传入的names，调用saveOrUpdate方法，</p>
<p>若meta表中无此分类则新增mata记录，并获取mid</p>
<p>若mid不为空，则往relationship表添加二者的对应cid、mid</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">saveOrUpdate</span><span class="params">(Integer cid, String name, String type)</span> </span>&#123;</span><br><span class="line">    MetaCond metaCond = <span class="keyword">new</span> MetaCond();</span><br><span class="line">    metaCond.setName(name);</span><br><span class="line">    metaCond.setType(type);</span><br><span class="line">    List&lt;Meta&gt; metas = <span class="keyword">this</span>.getMetas(metaCond);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">int</span> mid;</span><br><span class="line">    <span class="keyword">if</span>(metas.size() == <span class="number">1</span>)&#123;</span><br><span class="line">        Meta meta = metas.get(<span class="number">0</span>);</span><br><span class="line">        mid = meta.getMid();</span><br><span class="line">    &#125;<span class="keyword">else</span> <span class="keyword">if</span>(metas.size()&gt;<span class="number">1</span>)&#123;</span><br><span class="line">        <span class="comment">// 结果集不止一个</span></span><br><span class="line">        <span class="keyword">throw</span> BusinessException.withErrorCode(ErrorConstant.Meta.NOT_ONE_RESULT);</span><br><span class="line">    &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">        Meta meta = <span class="keyword">new</span> Meta();</span><br><span class="line">        meta.setName(name);</span><br><span class="line">        meta.setType(type);</span><br><span class="line">        <span class="comment">// 新增meta记录</span></span><br><span class="line">        <span class="keyword">this</span>.addMeta(meta);</span><br><span class="line">        mid = meta.getMid();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 添加文章分类的relationship</span></span><br><span class="line">    <span class="keyword">if</span>(mid != <span class="number">0</span>)&#123;</span><br><span class="line">        Long count = relationShipMapper.getCountById(cid, mid);</span><br><span class="line">        <span class="keyword">if</span>(count == <span class="number">0</span>)&#123;</span><br><span class="line">            RelationShip relationShip = <span class="keyword">new</span> RelationShip();</span><br><span class="line">            relationShip.setCid(cid);</span><br><span class="line">            relationShip.setMid(mid);</span><br><span class="line">            relationShipMapper.addRelationShip(relationShip);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>




<h3 id="3、文章列表页面"><a href="#3、文章列表页面" class="headerlink" title="3、文章列表页面"></a>3、文章列表页面</h3><p>文章列表页通常来说需要进行分页，以免数据量过大传输过慢</p>
<ul>
<li><p>引入pageHelper依赖</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.github.pagehelper<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>pagehelper-spring-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.2.12<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>


</li>
</ul>
<p>根据条件查找</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">contentService.getArticleByCond(<span class="keyword">new</span> ContentCond(), page, limit);</span><br><span class="line"></span><br><span class="line"><span class="comment">// xml sql</span></span><br><span class="line">select * from contents as c where c.categories like <span class="string">&#x27;%#&#123;categroy&#125;%&#x27;</span> and ...</span><br><span class="line">    order by c.created DESC</span><br></pre></td></tr></table></figure>


<h3 id="4、分类、标签管理"><a href="#4、分类、标签管理" class="headerlink" title="4、分类、标签管理"></a>4、分类、标签管理</h3><p><strong>查询分类</strong></p>
<p>控制器</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping(&quot;&quot;)</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">index</span><span class="params">(HttpServletRequest request)</span></span>&#123;</span><br><span class="line">    List&lt;MetaDto&gt; categories = metaService.getMetaList(Types.CATEGORY.getType(), <span class="keyword">null</span>, WebConst.MAX_POSTS);</span><br><span class="line">    List&lt;MetaDto&gt; tags = metaService.getMetaList(Types.TAG.getType(), <span class="keyword">null</span>, WebConst.MAX_POSTS);</span><br><span class="line">    request.setAttribute(<span class="string">&quot;categories&quot;</span>,categories);</span><br><span class="line">    request.setAttribute(<span class="string">&quot;tags&quot;</span>, tags);</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;admin/category&quot;</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>service</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> List&lt;MetaDto&gt; <span class="title">getMetaList</span><span class="params">(String type, String orderby, <span class="keyword">int</span> limit)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(StringUtils.hasLength(type))&#123;</span><br><span class="line">        orderby = <span class="string">&quot;count desc, a.mid desc&quot;</span>;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span>(limit&lt;<span class="number">1</span> || limit&gt; WebConst.MAX_POSTS)&#123;</span><br><span class="line">            limit=<span class="number">10</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        HashMap&lt;String , Object&gt; paraMap = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">        paraMap.put(<span class="string">&quot;type&quot;</span>, type);</span><br><span class="line">        paraMap.put(<span class="string">&quot;order&quot;</span>, orderby);</span><br><span class="line">        paraMap.put(<span class="string">&quot;limit&quot;</span>, limit);</span><br><span class="line">        <span class="keyword">return</span> metaMapper.selectFromSql(paraMap);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>mapper.xml</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">xml<span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">&quot;selectFromSql&quot;</span> <span class="attr">parameterType</span>=<span class="string">&quot;Map&quot;</span> <span class="attr">resultType</span>=<span class="string">&quot;com.learn.site.dto.MetaDto&quot;</span>&gt;</span></span><br><span class="line">    select m.*, count(r.cid) as count</span><br><span class="line">    from metas as m left join relationships as r on m.mid = r.mid</span><br><span class="line">    where m.type = #&#123;type&#125;</span><br><span class="line">    group by m.mid</span><br><span class="line">    order by #&#123;order&#125;</span><br><span class="line">    limit #&#123;limit&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br></pre></td></tr></table></figure>


<p><strong>添加分类</strong>、<strong>修改分类</strong></p>
<p>service层的业务逻辑：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">saveMeta</span><span class="params">(String type, String name, Integer mid)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(StringUtils.hasLength(type) &amp;&amp; StringUtils.hasLength(name))&#123;</span><br><span class="line">        MetaCond metaCond = <span class="keyword">new</span> MetaCond();</span><br><span class="line">        metaCond.setName(name);</span><br><span class="line">        List&lt;Meta&gt; metas = metaMapper.getMetaByCond(metaCond);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span>(<span class="keyword">null</span> == metas || metas.size() == <span class="number">0</span>)&#123;</span><br><span class="line">            Meta metaPojo = <span class="keyword">new</span> Meta();</span><br><span class="line">            metaPojo.setName(name);</span><br><span class="line">            <span class="keyword">if</span>(<span class="keyword">null</span> != mid)&#123;</span><br><span class="line">                <span class="comment">// mid不为空则为更新</span></span><br><span class="line">                Meta meta = metaMapper.getMetaById(mid);</span><br><span class="line">                <span class="keyword">if</span>(<span class="keyword">null</span> != meta) metaPojo.setMid(mid);</span><br><span class="line"></span><br><span class="line">                <span class="comment">//更新分类</span></span><br><span class="line">                metaMapper.updateMeta(metaPojo);</span><br><span class="line"></span><br><span class="line">                <span class="comment">//更新原有文章分类</span></span><br><span class="line">                <span class="keyword">if</span>(meta != <span class="keyword">null</span>)&#123;</span><br><span class="line">                    contentService.updateCategory(meta.getName(), name);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">                metaPojo.setType(type);</span><br><span class="line">                metaMapper.addMeta(metaPojo);</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">throw</span> BusinessException.withErrorCode(ErrorConstant.Meta.META_IS_EXIST);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>







      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2021/04/05/%E5%9B%9E%E6%BA%AF%E6%B3%95/" rel="next" title="回溯法">
                <i class="fa fa-chevron-left"></i> 回溯法
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2021/04/06/blog-%E4%BA%8C%E5%BC%80-%EF%BC%88%E4%BA%94%EF%BC%89%E5%90%8E%E5%8F%B0%E7%AE%A1%E7%90%86%E9%83%A8%E5%88%86%E5%AE%8C%E7%BB%93/" rel="prev" title="blog 二开 （五）后台管理部分完结">
                blog 二开 （五）后台管理部分完结 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.png"
                alt="" />
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
                <a href="/archives">
                  <span class="site-state-item-count">23</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">9</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%8E%E5%8F%B0%E7%AE%A1%E7%90%86%E5%8A%9F%E8%83%BD%EF%BC%9A%E6%B7%BB%E5%8A%A0%E5%88%86%E7%B1%BB%E3%80%81%E4%BF%AE%E6%94%B9%E5%88%86%E7%B1%BB"><span class="nav-text">后台管理功能：添加分类、修改分类</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1%E3%80%81%E5%8F%91%E8%A1%A8%E6%96%87%E7%AB%A0%EF%BC%88%E5%A2%9E%E5%8A%A0%E5%88%86%E7%B1%BB%EF%BC%89"><span class="nav-text">1、发表文章（增加分类）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93%E8%AE%BE%E8%AE%A1"><span class="nav-text">2、数据库设计</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3%E3%80%81%E6%96%87%E7%AB%A0%E5%88%97%E8%A1%A8%E9%A1%B5%E9%9D%A2"><span class="nav-text">3、文章列表页面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4%E3%80%81%E5%88%86%E7%B1%BB%E3%80%81%E6%A0%87%E7%AD%BE%E7%AE%A1%E7%90%86"><span class="nav-text">4、分类、标签管理</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yyc</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
